Help Olivia minimize the cost to transform one manuscript into another
Help Olivia find the minimum cost to transform manuscript1 into manuscript2 using insertion, deletion, or substitution, with costs provided as input.
m1:
m2:
Output: 10 (substitute o→a, o→c)
m1:
m2:
Output: 12 (multiple operations)
| \ | 0 | b | a |
|---|---|---|---|
| 0 | 0 | 4 | 8 |
| b | 3 | 0 | 4 |
| o | 6 | 3 | 5 |
Cost: 5 (substitute o→a)
For filling the DP table (n, m are string lengths)
For the DP table
m1:
m2:
Example 1: m1 = "book", m2 = "back", costs = [4, 3, 5] → 10
Example 2: m1 = "history", m2 = "mystery", costs = [2, 3, 4] → 12
For filling the DP table
For the DP table